096972d2b10d5a3df38c855f63a4e4340b1df136,spring-orm-hibernate4/src/test/java/org/springframework/orm/hibernate4/HibernateTransactionManagerTests.java,HibernateTransactionManagerTests,testParticipatingTransactionWithRollback,#,324
Before Change
public void testParticipatingTransactionWithRollback() throws Exception {
MockControl conControl = MockControl.createControl(Connection.class);
Connection con = (Connection) conControl.getMock();
MockControl sfControl = MockControl.createControl(SessionFactory.class);
final SessionFactory sf = (SessionFactory) sfControl.getMock();
MockControl sessionControl = MockControl.createControl(ImplementingSession.class);
ImplementingSession session = (ImplementingSession) sessionControl.getMock();
MockControl txControl = MockControl.createControl(Transaction.class);
Transaction tx = (Transaction) txControl.getMock();
sf.openSession();
sfControl.setReturnValue(session, 1);
session.beginTransaction();
sessionControl.setReturnValue(tx, 1);
session.close();
sessionControl.setReturnValue(null, 1);
tx.rollback();
txControl.setVoidCallable(1);
session.isConnected();
sessionControl.setReturnValue(true, 1);
session.connection();
sessionControl.setReturnValue(con, 2);
con.isReadOnly();
conControl.setReturnValue(false, 1);
sfControl.replay();
sessionControl.replay();
txControl.replay();
PlatformTransactionManager tm = new HibernateTransactionManager(sf);
final TransactionTemplate tt = new TransactionTemplate(tm);
try {
tt.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
return tt.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
throw new RuntimeException("application exception");
}
});
}
});
fail("Should have thrown RuntimeException");
}
catch (RuntimeException ex) {
// expected
}
sfControl.verify();
sessionControl.verify();
txControl.verify();
}
public void testParticipatingTransactionWithRollbackOnly() throws Exception {
After Change
@Test
public void testParticipatingTransactionWithRollback() throws Exception {
Connection con = mock(Connection.class);
final SessionFactory sf = mock(SessionFactory.class);
ImplementingSession session = mock(ImplementingSession.class);
Transaction tx = mock(Transaction.class);
given(sf.openSession()).willReturn(session);
given(session.beginTransaction()).willReturn(tx);
given(session.isOpen()).willReturn(true);
given(session.getFlushMode()).willReturn(FlushMode.AUTO);
given(session.isConnected()).willReturn(true);
given(session.connection()).willReturn(con);
PlatformTransactionManager tm = new HibernateTransactionManager(sf);
final TransactionTemplate tt = new TransactionTemplate(tm);
try {
tt.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
return tt.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
throw new RuntimeException("application exception");
}
});
}
});
fail("Should have thrown RuntimeException");
}
catch (RuntimeException ex) {
// expected
}
verify(session).close();
verify(tx).rollback();
}
@Test